const webpack = require('webpack');
const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
	entry: {
		app: './src/index.js'
	},
	plugins: [
	    new CleanWebpackPlugin(['dist']),
	    new webpack.HashedModuleIdsPlugin(),
	    new HtmlWebpackPlugin({
			title: 'Production',
			template: './src/html.js',
			hash: true,
    		xhtml: true
	    }),
		new webpack.ProvidePlugin({
	    	$: 'jquery',
	    	jQuery: 'jquery'
	    })
	],
	output: {
	    filename: '[name].[hash].js',
	    path: path.resolve(__dirname, 'dist')
	},
	resolve: {
		alias: {
			layout: path.resolve(__dirname, 'src/components/layout/html')
		}
	},
	module: {
		rules: [
			{
	    		test: /\.js$/,
	    		exclude: /(node_modules|bower_components)/,
	        	loader: 'babel-loader',
	        	query: {
	          		presets: ['es2015']
	        	}
	      	},
	      	{
	      		test: require.resolve('jquery'),
	      		loader: 'expose-loader?$!expose-loader?jQuery'
	      	},
			{
				test: /\.css$/,
				use: [
					'style-loader',
					'css-loader'
				]
			},
			{
		     	test: /\.ejs$/,
		    	loader: 'ejs-loader',
		    },
			{
				test: /\.(png|svg|jpg|gif)/,
				use: [
					'file-loader'
				]
			},
			{
				test: /\.(woff|woff2|eot|ttf|otf)$/,
				use: [
					'file-loader'
				]
			}
		]
	}
};
